/**
 * Created by IntelliJ IDEA.
 * User: mstine
 * Date: Mar 20, 2008
 * Time: 3:09:27 PM
 * To change this template use File | Settings | File Templates.
 */

//Checking for Overloaded Methods
class Greeting {
    def sayHello() {
        println "Hello, Stranger"
    }

    def sayHello(String name) {
        println "Hello, ${name}"
    }
}

def g = new Greeting()
if (g.metaClass.respondsTo(g, "sayHello", null)) {
    g.sayHello()
}

if (g.metaClass.respondsTo(g, "sayHello", String)) {
    g.sayHello("Memphis JUG")
}
println()

println "Number of sayHello() methods: " + g.metaClass.respondsTo(g, "sayHello").size() + "\n"

g.metaClass.respondsTo(g, "sayHello").each{m ->
    println "${m.name} ${m.nativeParameterTypes}"
}
println()

//Creating a Field Pointer
class PointerPerson {
    String name
    String getName() {
        "My name is ${name}"
    }
}

def p = new PointerPerson()
p.name = "Matt"
println p.name
println p.@name
println()

//Creating a Method Pointer
def list = []
def insert = list.&add
insert "Java"
insert "Groovy"
println list
println()

//GOTO: invokeMethod.groovy